<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: LJQ <245369209@qq.com> 
// +----------------------------------------------------------------------

namespace app\basic\model;
use app\common\model\Base;

/**
 * 企业
 */
class Enterprise extends Base{

	protected $name = "enterprise";
	protected $createTime = 'createTime';
	protected $updateTime = 'updateTime';

	public $enterpriseTypeList=[] ;

	/**
	 * 获取下拉菜单选项
	 * @param string $scope 数据范围
	 */
	public function getSelectList($scope){
		$where = [];
		if($scope){
			$where['id'] = $scope;
		}
		return $this->where($where)->column('fullName','id');
	}
	public function getPositionAttr($value,$data){
		$positionType = db('basicinfo')->where(array('sysCode'=>1))->column('subsystemName','subsystemNo');
		if($data['positionId']){
			return $positionType[$data['positionId']];
		}
		return null;
	}


	public  function getType(){

		$enterpriseType=db('basicinfo')->where(array('sysCode'=>3))->column('subsystemName','subsystemNo');
		$enterpriseType[0]='未选择';
		$this->enterpriseTypeList=$enterpriseType;
		return $this->enterpriseTypeList;
	}


	public function getProductionStatusAttr($value,$data){
		$this->getType();

		if($data['productionStatus']!==null){
			return $this->enterpriseTypeList[$data['productionStatus']];
		}
		return null;
	}

	public function getAreaAttr($value,$data){
		 $areaType = db('basicinfo')->where(['sysCode'=>2])->column('subsystemName','subsystemNo');
		 if($data['areaId']){
		 	return $areaType[$data['areaId']];
		 }
		 return null;
		 
	}
	
	public function getProductionAttr($value,$data){
		$productionStatusType = db('basicinfo')->where(array('sysCode'=>3))->column('subsystemName','subsystemNo');
		if($data['productionStatus']){
			return $productionStatusType[$data['productionStatus']];
		}
		return null;
	}
	
	public function getTypeAttr($value,$data){
		$enterpriseType = db('basicinfo')->where(array('sysCode'=>4))->column('subsystemName','id');
		if($data['typeId']){
			return $enterpriseType[$data['typeId']];
		}
		return null;
	}
	
	public function getUnitAttr($value,$data){
		$unitType = db('basicinfo')->where(array('sysCode'=>7))->column('subsystemName','subsystemNo');
		if($data['unitId']){
			return $unitType[$data['unitId']];
		}
		return null;
	}
	
	public function routes(){
		return $this->hasMany('route','enterpriseId','id');
	}
	
	public function warning(){
		return $this->hasOne('app\warning\model\Warning','enterpriseId','id');
	}
}